// 
// Bachelor of Software Engineering
// Media Design School
// Auckland
// New Zealand
//
// (c) 2005 - 2014 Media Design School
//
// File Name	: GameApp.h
// Desrciption	: CGameApp declaration file.
// Author		: Hayden Asplet.
// Mail			: hayden.asplet@mediadesignschool.com
//

#pragma once

#ifndef __GAMEAPP_H__
#define __GAMEAPP_H__

// Local Includes
#include "GameLogic.h"
#include "Sprite/Sprite.h"
#include "Sprite/BackBuffer.h"

#define WINDOW_CLASS_NAME L"WINCLASS1"

class CGameApp {
	// Member Functions
public:
	CGameApp();
	virtual ~CGameApp();

	// These functions must be overidden by derived 
	// classes in order to instantiate them.
	virtual CGameLogic* VCreateGame() = 0;
	virtual HICON VGetIcon() = 0;
	virtual TCHAR* VGetTitle() = 0;

	// These two functions are for initialization purposes only,
	// they should be overidden by derived classes to redefined
	// the window size and style.
	virtual CPoint VGetScreenSetupSize();
	virtual DWORD VGetWindowStyle();

	// Win32 Specific Functions
	HWND GetHwnd() const;
	HINSTANCE GetInstance() const;

	virtual bool VInitialize(HINSTANCE _hInstance, 
							 LPSTR _lpCmdLine, 
							 HWND _hWnd = NULL,
							 int _iFrameRate = g_kiFRAMES_PER_SEC);

	static LRESULT CALLBACK MsgProc(HWND _hWnd, UINT _msg, WPARAM _wParam, LPARAM _lParam); // The message handler.

	// Game Application Functions
	void Update();
	LRESULT OnClose();				// Clean up.

	CSprite LoadSprite(int _id);
	CSprite LoadSprite(const std::string& _krstrFileName);
	void RenderSprite(const CSprite& _sprite, const CPoint& _krPosition, int _iFrame = 0);
	void RenderSprite(const CSprite& _sprite, int _iX, int _iY, int _iFrame = 0);

	void RenderText(const std::string& _krstrText, 
					int _iX, int _iY, 
					TColour _colour, 
					int _iHeight, 
					const std::string& _krstrFont);

	void UpdateScreenSize(const CPoint& _screenSize);
	CPoint GetScreenSize() const;
	bool IsRunning() const;

	void SetFrameRateShowing(bool _bIsShowing);
protected:
private:
	// Disallow copying.
	CGameApp(const CGameApp& _appOther);
	CGameApp& operator=(const CGameApp& _appOther);

	void Render();

	// Member Variables
public:
	CGameLogic* m_pGame;		// The game logic.

protected:
	HWND m_hWnd;				// The handle to the window.
	HINSTANCE m_hInstance;		// The handle to the instance.

	CBackBuffer* m_pBackBuffer;		// The app's backbuffer;

	bool m_bIsRunning;			// True if the app is running, false otherwise.
	bool m_bShowFrameRate;		// True if the frame should be shown, false if not (debug only).
	CPoint m_screenSize;		// The app's screen size.
	float m_fDeltaTime;			// The time of the last tick.
	int m_iFrameRate;			// The frame rate to lock the game tick at in frames per second.
private:
};

extern CGameApp* g_pApp;

#endif